<template>
  <div class="case">
    <na-table
      :datas.sync="tableData"
      :searchObj.sync="search"
      @updateDatas="getAllMaterils"
      @newAdd="newAddClick"
    >
    </na-table>
    <!-- 人员寻找弹框   -->
    <per-redio-dialog
      :per-visible.sync="isperShow"
      @getEmployee="getEmployee"
    />
    <!-- 选择订单弹窗 -->
    <selectDataOrder
      :per-visible.sync="showOrder"
      @current="selectCurrentRow"
    />
    <!-- 数据下单弹窗 -->
    <el-dialog
      :title="tname"
      :visible.sync="isAddProduct"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog"
      width="85%"
      @close="closeDialog"
      destroy-on-close
      @open="openCp"
    >
      <div class="dialogDody">
        <div class="subTip">
          <span class="mr15"
            ><span class="mr5">数据单号：</span
            >{{ ProductForm.dataBillNo || "系统自动生成" }}</span
          >
          <span class="mr15"
            ><span class="mr5">创建日期：</span
            >{{ ProductForm.createDate || dayjs().format("YYYY-MM-DD") }}</span
          >
          <span class="mr15"
            ><span class="mr5">创建人员：</span
            >{{ opsid != 1 ? ProductForm.createPersonName : name }}</span
          >
        </div>
        <div class="addWuliaoBox">
          <el-form
            ref="ProductForm"
            :model="ProductForm"
            :rules="rules"
            label-width="110px"
            label-position="left"
            class="dialogForm dialogInlineForm"
            :disabled="canDiable"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="数据来源" prop="dataComeFromName">
                  <el-input
                    v-model="ProductForm.dataComeFromName"
                    placeholder="数据来源"
                    size="mini"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="数据状态" prop="dataBillState">
                  <el-select
                    filterable
                    v-model="ProductForm.dataBillState"
                    placeholder="数据状态"
                    size="mini"
                    @change="supplierChange"
                  >
                    <el-option
                      v-for="(item,index) in stateDataList"
                      :key="index"
                      :label="item.name"
                      :value="item.code"
                    />
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="到达日期">
                  <el-date-picker
                    v-model="ProductForm.dataArriveDate"
                    type="date"
                    :picker-options="option"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期"
                    size="mini"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="数据颜色">
                  <el-select
                    v-model="ProductForm.dataColor"
                    placeholder="数据颜色"
                    size="mini"
                    @change="supplierChange"
                    filterable
                  >
                    <el-option
                      v-for="(item,index) in colorDataList"
                      :key="index"
                      :label="item.objectName"
                      :value="item.objectCode"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="数据格式">
                  <el-select
                    v-model="ProductForm.dataFormat"
                    placeholder="数据格式"
                    size="mini"
                    filterable
                    @change="supplierChange"
                  >
                    <el-option
                      v-for="(item,index) in formDataList"
                      :key="index"
                      :label="item.objectName"
                      :value="item.objectCode"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="数据到达数量">
                  <el-input
                    v-model="ProductForm.arriveDataQuantity"
                    placeholder="数据到达数量"
                    size="mini"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="订单单号" prop="saleOrderNo">
                  <el-input
                    v-model="ProductForm.saleOrderNo"
                    disabled
                    placeholder="订单单号"
                    size="mini"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="协议书号" prop="xieYiShuHao">
                  <el-input
                    v-model="ProductForm.xieYiShuHao"
                    disabled
                    placeholder="协议书号"
                    size="mini"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="客户单号" prop="customerBillNo">
                  <el-input
                    v-model="ProductForm.customerBillNo"
                    disabled
                    placeholder="客户单号"
                    size="mini"
                  />
                </el-form-item>
              </el-col>
              
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="产品名称" prop="orderProductName">
                  <el-input
                    v-model="ProductForm.orderProductName"
                    disabled
                    placeholder="产品名称"
                    size="mini"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="生产数量" prop="tagDataQuantity">
                  <el-input
                    v-model="ProductForm.tagDataQuantity"
                    disabled
                    placeholder="生产数量"
                    size="mini"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="页面长度" prop="pageLength">
                  <el-input
                    v-model="ProductForm.pageLength"
                    placeholder="页面长度"
                    size="mini"
                  />
                </el-form-item>
              </el-col>
              
            </el-row>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="总页面数" prop="totalPageCount">
                    <el-input
                      v-model="ProductForm.totalPageCount"
                      placeholder="总页面数"
                      size="mini"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            <el-form-item label="数据路径" class="inlineText">
              <el-input
                id="code"
                v-model="ProductForm.dataPath"
                placeholder="数据路径"
                size="mini"
              >
                <template slot="append">
                  <el-button
                    id="copy_text"
                    ref="copy"
                    data-clipboard-action="copy"
                    :data-clipboard-text="ProductForm.dataPath"
                    @click="copy"
                    >复制路径</el-button
                  >
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="数据名称" class="inlineText">
              <el-input
                v-model="ProductForm.dataName"
                type="textarea"
                :rows="5"
                placeholder="数据名称"
                size="mini"
                clearable
              />
            </el-form-item>

            <el-form-item
              label="自检流程"
              class="inlineText"
              prop="inspectProcess"
            >
              <div>
                <div />
                <div class="tagsWapper w100 flex_between">
                  <div>
                    <el-tag
                      v-for="(tags,i) in dataList"
                      :key="i"
                      class="mr15 pointer"
                      type="info"
                      effect="plain"
                      @click="addTag(tags)"
                    >
                      {{ tags.objectName }}
                    </el-tag>
                  </div>
                  <el-tag
                    v-if="!canDiable"
                    type="info"
                    class="pointer"
                    @click="cleartags"
                    >{{ "清空" }}
                  </el-tag>
                </div>
                <div class="selectTgs">
                  <div
                    v-for="(tag, index) in ProductForm.inspectProcess"
                    :key="index"
                    class="flex"
                  >
                    <el-tag closable @close="handleClose(tag)">
                      {{ tag.inspectProcessName }}
                    </el-tag>
                    <span
                      v-if="index + 1 < ProductForm.inspectProcess.length"
                      class="right"
                    >
                      >
                    </span>
                  </div>
                </div>
              </div>
            </el-form-item>

            <el-form-item label="数据备注" class="inlineText" prop="dataRemark">
              <el-input
                v-model="ProductForm.dataRemark"
                type="textarea"
                :rows="5"
                placeholder="数据备注"
                size="mini"
                clearable
              />
            </el-form-item>
          </el-form>
          <div class="item">
            <div class="item-title">
              <h3>明细</h3>
            </div>
            <div class="item-content">
              <el-table
                :data="ProductForm.dataProduceBillMxList"
                border
                style="width: 100%"
              >
                <el-table-column type="index" label="序号" width="50" />
                <el-table-column prop="prop1" align="left"  width="140" label="适用机台">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.machineCode"
                      placeholder="请选择"
                      size="small"
                      :disabled="disabled"
                      filterable
                      @change="
                        handleMachineChange(scope.row, scope.$index, $event)
                      "
                    >
                      <el-option
                        v-for="item in allMaterielClass"
                        :key="item.machineCode"
                        :label="item.machineName"
                        :value="item.machineCode"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="prop2"
                  align="left"
                  label="卷"
                  width="100"
                >
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.roll"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="prop4"
                  align="left"
                  label="编号"
                  width="160"
                >
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.serialNumber"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="prop7"
                  align="left"
                  label="文件名"
                  width="160"
                >
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.fileName"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="prop8"
                  align="left"
                  label="页数"
                  width="140"
                >
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.pageCount"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="prop8"
                  align="left"
                  label="总页数"
                  width="140"
                >
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.totalPageCount"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="prop5" 
                width="140" align="left" label="起始号">
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.startNumber"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="prop5" 
                width="140" align="left" label="截至号">
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.endNumber"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="prop5" 
                width="160" align="left" label="打印时间">
                  <template slot-scope="scope">
                    <el-date-picker
                    :disabled="disabled"
                      v-model="scope.row.printingTime"
                      type="date"
                      size="small"
                      style="width:100%"
                      value-format="yyyy-MM-dd"
                      placeholder="选择日期">
                    </el-date-picker>
                  </template>
                </el-table-column>
                <el-table-column prop="prop5" 
                width="220"  align="left" label="备注">
                  <template slot-scope="scope">
                    <el-input
                      :disabled="disabled"
                      v-model="scope.row.remark"
                      placeholder="请输入"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="100px"
                  fixed="right"
                  align="center"
                  v-if="!disabled"
                >
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      @click="handleCopy(scope.row, scope.$index, 3)"
                      v-if="
                        ProductForm.dataProduceBillMxList.length - 1 !=
                        scope.$index
                      "
                    >
                      <p>复制</p>
                    </el-button>
                    <el-button
                      type="text"
                      @click="handleDelete(scope.row, scope.$index, 3)"
                      v-if="
                        ProductForm.dataProduceBillMxList.length - 1 !=
                        scope.$index
                      "
                    >
                      <p>删除</p>
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isAddProduct = false">取 消</el-button>
        <el-button size="mini" @click="checkGD">查看工单</el-button>
        <!-- 新增       -->
        <el-button
          v-if="opsid !== 2"
          :loading="addProductLoading"
          :disabled="addProductLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="savell"
          >仅保存</el-button
        >
        <el-button
          v-if="opsid !== 2"
          :loading="btnLoding"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="mini"
          @click="handleFinish"
          >{{ btm }}</el-button
        >
      </div>
    </el-dialog>
    <!-- 查看工单 -->
    <orderInfo
      ref="orderInfo"
      :per-visible.sync="orderShow"
      :productdd="orderObj"
    />

    <el-dialog
      title="查看工单"
      :visible.sync="seeOrder"
      :close-on-click-modal="false"
      :fullscreen="true"
      custom-class="bodyNoPadDialog "
    >
    <iframe ref="myIframe" :src="'/#/production/productionOrderNewDetail?produceTaskBillNo='+ProductForm.produceTaskBillNo+'&productCode='+ProductForm.productCode+'&typeStatus=1&isIframe='+true" style="width:100%;height:100%" frameborder="0"></iframe>
  </el-dialog>
  </div>
</template>
<script>
import { arraySort } from "@/utils";
import perRedioDialog from "@/components/perDialogRedio";
import selectDataOrder from "@/components/selectDataOrder";
import orderInfo from "./orderInfo";
import Clipboard from "clipboard";
import naTable from "@/components/naTable";
import { mapGetters } from "vuex";
import screec from "@/components/screen";
export default {
  name: "dataManage",
  components: {
    naTable,
    perRedioDialog,
    selectDataOrder,
    orderInfo,
    screec,
  },
  data() {
    return {
      ops: "add", // 操作、新建，修改，查看
      opsid: 1, // 3 确定 1 新建， 4 修改， 2 查看
      tableHeight: null, // 表格最大高度
      showOrder: false,
      searchLoading: false, // 搜索加载效果
      seeOrder:false,
      allMaterirls: [], // 全部数据列表
      addLoading: false,
      selectRow: null,
      isNopassshow: false,
      btnLoding: false,
      equipmentList: [],
      orderObj: {},
      orderShow: false,
      passForm: {
        cancelReason: "",
      },
      disabled: false,
      // 表格操作
      ProductForm: {
        inspectProcess: [],
        dataProduceBillMxList: [
          {
            dataProduceBillMxID: 0,
            dataProduceBillMxCode: "",
            dataProduceBillNo: "",
            createDate: "",
            machineCode: "",
            roll: "",
            serialNumber: "",
            fileName: "",
            startNumber: "",
            endNumber: "",
            pageCount: "",
            totalPageCount: "",
            remark: "",
            printingTime: "",
          },
        ],
      },
      // 搜索条件
      search: {
        QueryDataBaseFiled: "",
        pageIndex: 1,
        pageSize: 30,
        likeWords: "",
      },
      allMaterielClass: [], //机台
      total: 0, // 总条数
      tableHead: [], // 表格表头
      addProductLoading: false,
      isAddProduct: false,
      isperShow: false,
      isSemidialog: false,
      multipleSelection: null,
      canDiable: false,
      rules: {
        dataArriveDate: [
          {
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
        dataColor: [
          {
            required: true,
            message: "请选择数据颜色",
            trigger: "change",
          },
        ],
        dataFormat: [
          {
            required: true,
            message: "请选择数据格式",
            trigger: "change",
          },
        ],
        dataPath: [
          {
            required: true,
            message: "请输入数据路径",
            trigger: "change",
          },
        ],
        dataName: [
          {
            required: true,
            message: "请输入数据名称",
            trigger: "change",
          },
        ],
        arriveDataQuantity: [
          {
            required: true,
            message: "请输入数据到达数量",
            trigger: "change",
          },
        ],
      },
      option: {
        disabledDate: (time) => {
          return time.getTime() < Date.now() - 1 * 24 * 3600 * 1000;
        },
      },
      dataList: [],
      colorDataList: [],
      formDataList: [],
      stateDataList: [
        {
          code: 1,
          name: "已到达",
        },
        {
          code: 2,
          name: "制作中",
        },
        {
          code: 0,
          name: "未到达",
        },
      ],
      tagsList: [],

      tableData: {
        headId: "head", //表头列显隐组件所需ID-避免多个页面id重复问题
        tableId: "dataBillID", //表格列表key,也就是一条数据的唯一标识
        senior: false, //高级搜索是否显示
        addPermission: "MenuCode3-1-1", //新建按钮权限
        disableWord: "", //是否禁用显示的字段
        disableStatus: "", //判断未禁用的状态值
        //表格按钮
        operationBtn: [
          {
            title: "查看",
            methodsName: "handleClick",
          },
          {
            title: "编辑",
            methodsName: "handleUpdata",
            permission: "MenuCode3-1-2",
            hideCondition: {
              //按钮显隐条件
              prop: "dataBillState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用
                0, 1, 2,
              ],
            },
          },
          {
            title: "完成",
            methodsName: "handleConfirm",
            permission: "MenuCode3-1-3",
            hideCondition: {
              //按钮显隐条件
              prop: "dataBillState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用
                0, 1, 2,
              ],
            },
          },
          {
            title: "删除",
            methodsName: "handleDeleteRow",
            permission: "MenuCode3-1-4",
            hideCondition: {
              //按钮显隐条件
              prop: "dataBillState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用
                0, 1, 2,
              ],
            },
          },
        ],
        //表格内容
        tbody: [],
        //表格表头
        thead: [],
      },
    };
  },
  computed: {
    ...mapGetters(["name", "userInfo"]),
    btm() {
      if (this.opsid === 5) {
        return "确认";
      } else {
        return "保存并确定";
      }
    },
    tname() {
      if (this.opsid === 1) {
        return "新建数据下单";
      } else if (this.opsid === 2) {
        return "查看数据下单";
      } else if (this.opsid === 3) {
        return "确定数据下单";
      } else if (this.opsid === 4) {
        return "修改数据下单";
      } else {
        return "到达数据下单";
      }
    },
  },
  created() {
    //  所有列表数据
    this.getAllMaterils();
    // 表格得表头
    this.getTableHead();
    if (this.$route.query.openADD) {
      const row = this.$route.query.item;
      this.ops = "add";
      this.isAddProduct = true;
      this.ProductForm.produceTaskBillNo = row.produceTaskBillNo;
      this.ProductForm.saleOrderNo = row.saleOrderNo;
      this.openCp();
    }
    this.getMaterielClass();
  },
  methods: {
    // 复制
    copy() {
      var clipboard = new Clipboard("#copy_text");
      console.log(clipboard, 111);
      clipboard.on("success", (e) => {
        this.$message({
          message: "复制成功",
          type: "success",
        });
        clipboard.destroy();
      });
      clipboard.on("error", (e) => {
        // 释放内存
        clipboard.destroy();
      });
    },

    //机台选择事件
    handleMachineChange(row, index, e) {
      if (index == this.ProductForm.dataProduceBillMxList.length - 1) {
        this.ProductForm.dataProduceBillMxList.push({
          dataProduceBillMxID: 0,
          dataProduceBillMxCode: "",
          dataProduceBillNo: "",
          createDate: "",
          machineCode: "",
          roll: "",
          serialNumber: "",
          fileName: "",
          startNumber: "",
          endNumber: "",
          pageCount: "",
          totalPageCount: "",
          remark: "",
          printingTime: "",
        });
      }
    },

    // 获取所有设备
    getMaterielClass() {
      this.$api.product
        .GetMatchProductDevices({
          likeWords: "",
          machineState: 1,
        })
        .then((res) => {
          this.allMaterielClass = res;
        });
    },

    // 清楚tags
    cleartags() {
      if (this.opsid === 4 || this.opsid === 1) {
        this.ProductForm.inspectProcess = [];
      }
    },
    addTag(tags) {
      if (this.opsid === 4 || this.opsid === 1) {
        this.ProductForm.inspectProcess.push({
          inspectProcessCode: tags.objectCode,
          inspectProcessName: tags.objectName,
        });
      }
    },
    handleClose(tag) {
      if (this.opsid === 4 || this.opsid === 1) {
        this.ProductForm.inspectProcess.splice(
          this.ProductForm.inspectProcess.indexOf(tag),
          1
        );
      }
    },
    // selectCurrentRow(row) {
    //   this.ops = 'add'
    //   this.isAddProduct = true
    //   this.ProductForm.tagDataQuantity = row.tagDataQuantity
    //   this.ProductForm.saleOrderNo = row.saleOrderNo
    //   this.ProductForm.dataComeFromName = row.dataComeFromName
    //   this.ProductForm.customerBillNo = row.customerBillNo
    //   this.ProductForm.orderProductName = row.orderProductName
    //   this.ProductForm.dataArriveDate = row.orderCreateTime
    //   this.ProductForm.xieYiShuHao = row.xieYiShuHao
    // },
    openCp() {
      this.getProcessDataList();
      this.getDataColorDataList();
      this.getDataFormatDataList();
    },
    getProcessDataList() {
      this.$api.data
        .GetDataProducesInspectProcessDataList()
        .then((res) => {
          this.dataList = res;
        })
        .catch(() => {});
    },

    getDataColorDataList() {
      this.$api.data
        .GetDataProducesDataColorDataList()
        .then((res) => {
          this.colorDataList = res;
        })
        .catch(() => {});
    },

    getDataFormatDataList() {
      this.$api.data
        .GetDataProducesDataFormatDataList()
        .then((res) => {
          this.formDataList = res;
        })
        .catch(() => {});
    },

    closePassDialog() {
      this.passForm.cancelReason = "";
      this.selectRow = null;
    },

    checkProductList(row) {
      this.opsid = 2;
      this.canDiable = true;
      this.getDetail(row);
      // this.$router.push({
      //   path: '/business/orderDetail', // 跳转的路径
      //   query: {
      //     tabIndex: 4,
      //     saleOrderNo: row.saleOrderNo,
      //     lltype: '0'
      //   }
      // })
    },
    // 新建点击事件
    newAddClick() {
      // this.isAddProduct = true
      this.ops = "add";
      this.opsid = 1;
      this.showOrder = true;
      this.canDiable = false;
    },
    handleClick(row) {
      this.opsid = 2;
      this.canDiable = true;
      this.stateDataList.push({
        code: 3,
        name: "已完成",
      });
      this.getDetail(row);
    },
    handleConfirm(row) {
      this.opsid = 5;
      this.canDiable = true;
      this.getDetail(row);
    },

    //完成
    handleFinish() {
      const parmas = this.ProductForm;
      if (this.opsid == 1) {
        this.$confirm("该单据点击完成后不可修改编辑，是否继续 ", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          this.$refs.ProductForm.validate((valid) => {
            if (valid) {
              this.btnLoding = true;
              this.ProductForm.dataProduceBillMxList.pop()
              this.$api.data
                .CreateDataProduceBill(parmas)
                .then((res) => {
                  this.btnLoding = false;
                  this.ProductForm.dataBillID = res;
                    
                  this.$api.data
                    .FinishedDataProduceBill(this.ProductForm)
                    .then(() => {
                      this.isAddProduct = false;
                      this.getAllMaterils();
                      this.$message({
                        message: "完成成功",
                        type: "success",
                      });
                    })
                    .catch(() => {
                      this.btnLoding = false;
                    });
                })
                .catch(() => {
                  this.btnLoding = false;
                });
            }
          });
        });
      } else {
        this.$confirm("该单据点击完成后不可修改编辑，是否继续 ", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          this.$refs.ProductForm.validate((valid) => {
            if (valid) {
              this.$api.data
                .FinishedDataProduceBill(parmas)
                .then(() => {
                  this.btnLoding = false;
                  this.isAddProduct = false;
                  this.getAllMaterils();
                  this.$message({
                    message: "完成成功",
                    type: "success",
                  });
                })
                .catch(() => {
                  this.btnLoding = false;
                });
            }
          });
        });
      }
    },
    handleUpdata(row) {
      this.opsid = 4;
      this.canDiable = false;
      this.getDetail(row);
    },
    handleDeleteRow(row) {
      const _data = {
        dataBillID: row.dataBillID,
      };
      this.$confirm("确定删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.data
          .DeleteDataProduceBill(_data)
          .then(() => {
            this.getAllMaterils();
            this.$message({
              message: "删除成功",
              type: "success",
            });
          })
          .catch(() => {});
      });
    },
    getDetail(row) {
      const _data = {
        dataBillID: row.dataBillID,
        dataBillNo: row.dataBillNo,
      };
      this.$api.data.GetDataProduceBillDetail(_data).then((res) => {
        this.ProductForm = res;
        console.log(this.ProductForm.produceTaskBillNo)
        if(this.opsid == 4){
          this.ProductForm.dataProduceBillMxList.push({
          dataProduceBillMxID: 0,
          dataProduceBillMxCode: "",
          dataProduceBillNo: "",
          createDate: "",
          machineCode: "",
          roll: "",
          serialNumber: "",
          fileName: "",
          startNumber: "",
          endNumber: "",
          pageCount: "",
          totalPageCount: "",
          remark: "",
          printingTime: "",
        });
        }
        this.isAddProduct = true;
      });
    },
    selectCurrentRow(row) {
      this.ops = "add";
      this.isAddProduct = true;
      this.ProductForm.tagDataQuantity = row.tagDataQuantity;
      this.ProductForm.saleOrderNo = row.saleOrderNo;
      this.ProductForm.saleOrderCode = row.saleOrderCode;
      this.ProductForm.dataComeFromName = row.dataComeFromName;
      this.ProductForm.customerBillNo = row.customerBillNo;
      this.ProductForm.orderProductName = row.orderProductName;
      this.ProductForm.dataArriveDate = row.orderCreateTime;
      this.ProductForm.xieYiShuHao = row.xieYiShuHao;
      this.ProductForm.produceTaskBillNo = row.produceTaskBillNo;
      this.ProductForm.productCode = row.productCode;
    },

    // 查看工单
    checkGD() {
      this.seeOrder = true
      this.$refs.myIframe.contentWindow.location.reload(true);
      // this.$router.push({
      //   path: "/production/productionOrderNewDetail", // 跳转的路径
      //   query: {
      //     produceTaskBillNo: this.ProductForm.produceTaskBillNo,
      //     productCode: this.ProductForm.productCode,
      //     typeStatus: 1,
      //   },
      // });
    },

    //复制
    handleCopy(row, index, type) {
      this.ProductForm.dataProduceBillMxList.splice(
          index,
          0,
          JSON.parse(JSON.stringify(row))
        );
    },

    //删除
    handleDelete(row, index, type) {
      this.ProductForm.dataProduceBillMxList.splice(index, 1);
    },

    savell() {
      const parmas = this.ProductForm;
      this.ProductForm.dataProduceBillMxList.pop()
      if (this.opsid === 4) {
        this.$refs.ProductForm.validate((valid) => {
          if (valid) {
            this.addProductLoading = true;
            this.$api.data
              .UpdateDataProduceBill(parmas)
              .then(() => {
                this.addProductLoading = false;
                this.isAddProduct = false;
                this.getAllMaterils();
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addProductLoading = false;
                this.ProductForm.dataProduceBillMxList.push({
                  dataProduceBillMxID: 0,
                  dataProduceBillMxCode: "",
                  dataProduceBillNo: "",
                  createDate: "",
                  machineCode: "",
                  roll: "",
                  serialNumber: "",
                  fileName: "",
                  startNumber: "",
                  endNumber: "",
                  pageCount: "",
                  totalPageCount: "",
                  remark: "",
                  printingTime: "",
                });
              });
          }
        });
      } else {
        this.ProductForm.dataProduceBillMxList.forEach((item)=>{
          item.createDate = this.dayjs().format("YYYY-MM-DD");
        })
        this.$refs.ProductForm.validate((valid) => {
          if (valid) {
            this.addProductLoading = true;
            this.$api.data
              .CreateDataProduceBill(parmas)
              .then(() => {
                this.addProductLoading = false;
                this.isAddProduct = false;
                this.getAllMaterils();
                this.$message({
                  message: "保存成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addProductLoading = false;
                this.ProductForm.dataProduceBillMxList.push({
                  dataProduceBillMxID: 0,
                  dataProduceBillMxCode: "",
                  dataProduceBillNo: "",
                  createDate: "",
                  machineCode: "",
                  roll: "",
                  serialNumber: "",
                  fileName: "",
                  startNumber: "",
                  endNumber: "",
                  pageCount: "",
                  totalPageCount: "",
                  remark: "",
                  printingTime: "",
                });
              });
          }
        });
      }
    },
    // 得到申请人员
    getEmployee(val) {
      this.ProductForm.getProductPersonName = val.employeeName;
      this.ProductForm.getProductPerson = val.employeeCode;
    },
    supplierChange(val) {},
    // 获取表格表头
    getTableHead() {
      const parmas = {
        tableCode: this.$config.dataproducebilllist,
      };
      this.$api.common.getAllTableHead(parmas).then((res) => {
        res.sort(arraySort("columnSort"));
        this.tableData.thead = res;
      });
    },
    // 所有列表数据
    getAllMaterils() {
      const parmas = this.search;
      this.searchLoading = true;
      this.$api.data
        .GetPageDataProduceBillDataList(parmas)
        .then((res) => {
          this.tableData.tbody = res.list;
          this.search.total = res.totalCount;
          this.searchLoading = false;
        })
        .catch(() => {
          this.searchLoading = false;
        });
    },
    // 新建弹框关闭事件
    closeDialog() {
      if (this.$refs.ProductForm) {
        this.$refs.ProductForm.resetFields();
      }
      this.ProductForm = this.$options.data().ProductForm;
      this.stateDataList = this.$options.data().stateDataList;
    },
  },
};
</script>
<style lang="scss" scoped>
.container {
  height: 100%;
}

.permangeRg {
  border: 1px solid #e6e6e6;
  background: #fff;
  height: 100%;

  .mainTT {
    font-size: 16px;
    font-weight: bold;
    width: 100%;
    padding: 18px 16px;
    padding-bottom: 0;
  }
}

.addWuliaoBox {
  padding: 10px 16px;

  .tableBox {
    margin-top: 16px;
    border: 1px solid #e6e6e6;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    overflow: hidden;

    .tt {
      height: 38px;
      line-height: 38px;
      padding-left: 16px;
      background: #f7f8fa;
      border-radius: 8px 8px 0 0;
    }
  }
}

.inlineText {
  margin: 10px 0;
}

.tagsWapper {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  background-color: #f5f6f9;
  padding: 10px;
  border: 1px solid #e6e6e6;
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
}

.selectTgs {
  display: flex;
  flex-wrap: wrap;
  padding: 10px;
  border: 1px solid #e6e6e6;
  border-radius: 0 0 4px 4px;

  .right {
    padding: 0 10px;
  }
}

.subTip {
  border-bottom: 1px #e6e6e6 solid;
  background: #f5f6f9;
  padding: 8px 16px;
}
</style>
